#ifndef CLIENTNET_H
#define CLIENTNET_H

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

#include <QDebug>
#include <QTcpSocket>
#include <QWidget>

class ClientNet : public QWidget
{
public:
    ClientNet(QWidget *parent = nullptr);
    static ClientNet* NewInstance();

public:
    //发送string
    bool sendMsg(std::string msg);

public:
    //通过qt自己封装的socket连接
    bool connectByQtSocket();
    //通过原生socket api连接，暂时废弃
    bool connectByRawSocket();

public slots:
    //接受string
    void slotRecvMsg();


public:
//    const char IP[16] = "127.0.0.1";
    const char IP[16] = "120.78.183.9";
//    const char IP[16] = "172.18.168.144";
    const int PORT = 7701;
    const int MAXBUFFER = 4096;

private:
    static ClientNet* singleObj;
    int connfd;
    QTcpSocket* conn;
};

#endif // CLIENTNET_H
